<?php 
/* ================================================================================
 * Events Calendar 
 *
 * main.php: This is the main file for Living Web.
 *
 * Author: Eric Hendrickson (enhendrickson@liberty.edu)
 * Date: 7/20/06
   ================================================================================ */
	
	global $SSO, $Security, $AppID, $User, $DB;
	//Check to see if there is a valid session 
	$SessionInfo = $SSO->isValidSession("index.php?action=login", $SSO->getSessionInformation());	
	
	//Check to see if the user has rights to be on LivingWeb
	$PageRights = array('ADMIN');
	$UserRoles = $Security->ValidateUser($SessionInfo['username'], $AppID, $PageRights, 1);
		
	//Grab the user info
	$UserInfo = $User->GetUserInfo($SessionInfo['username']);	
	
	if(isset($_POST['btnSubmit']))
	{
		if(trim($_POST['end_calendar']) == '')
		{
			$_POST['end_calendar'] = $_POST['start_calendar'];
		}
		
		$value_array = 			array (
				'created_date'		=> 'NOW()',
				'event_start_date'		=> 		$_POST['start_calendar'].' '.$_POST['start_time'],
				'event_end_date'		=> 		$_POST['end_calendar'].' '.$_POST['end_time'],
				'event_title'		=> str_replace("\\","",$_POST['txtEventTitle']),
				'event_description'		=> str_replace("\\","",$_POST['txtEventDescription']),
				'event_location'		=> str_replace("\\","",$_POST['txtEventLocation']),
				'created_user'		=> $SessionInfo['username']);

		if(!isset($_GET['id']) || trim($_GET['id']) == "") {
			$db_string = $DB->compile_db_insert_string($value_array);
			$DB->query("INSERT INTO calendar_events (".$db_string['FIELD_NAMES'].") VALUES (".$db_string['FIELD_VALUES'].")");
		}
		if(isset($_GET['id'])) {
			$db_string = $DB->compile_db_update_string($value_array);
			$DB->query("UPDATE calendar_events SET " . $db_string . " WHERE event_id = '" . $_GET['id'] . "'");
		}
	}
	
	header("Location: index.php?action=main");
		
	function getDateForMysqlDateField($date) 
	{
		list($month, $day, $year) = split('[/.-]', $date);
		return $year."-".$month."-".$day;
	}
?>